package examples.controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFileChooser;
import org.fife.ui.rtextarea.SearchContext;
import org.fife.ui.rtextarea.SearchEngine;

import com.pinapel.aixml.controller.MainController;

import examples.vista.FileChooserView;
import examples.vista.TextEditorView_useless;


public class TextEditorController_useless implements ActionListener{

	private TextEditorView_useless mTEW;
	private MainController mainController;
	
	
	public void actionPerformed(ActionEvent e) {
		
		String command = e.getActionCommand();
		if((command.compareTo("FindNext")==0) || (command.compareTo("FindPrev")==0)){
			
			// "FindNext" => search forward, "FindPrev" => search backward
			boolean forward = "FindNext".equals(command);
			boolean backward = "FindPrev".equals(command);
			
			// Create an object defining our search parameters.
			SearchContext context = new SearchContext();
			String text = mTEW.getSearchField().getText();
			if (text.length() == 0) {
				return;
			}
			context.setSearchFor(text);
			context.setMatchCase(mTEW.getMatchCaseCB().isSelected());
			context.setRegularExpression(mTEW.getRegexCB().isSelected());
			context.setSearchForward(forward);
			context.setWholeWord(false);
			
			boolean found = SearchEngine.find(mTEW.getTextArea(), context);
			if (!found) {
				mTEW.notFound();
			}
		}
	}

	public void setmTEW(TextEditorView_useless mTEW) {
		this.mTEW = mTEW;
	}

}
